Last Update: 07.08.2021
By: Ovunc Tukenmez
Email: ovunct@live.com
Thank you for purchasing this PHP software. If you have any question that is beyond the scope of this help file, please feel free to send me an email. Thanks!
CryptoBot For Binance - Cryptocurrency Trading PHP Script is an advanced PHP software
to automate trading of crypto coins in Binance crypto-currency exchange. By
following defined rules of the trading strategy of the user, it aims to facilitate repetitive trade process fast
using API provided by Binance platform.
The software provides web interface to make possible instant user actions on going process if needed.
SQLite database is used to make installation, setup and migration a smooth/easy process.
The internet browser based interface use the system's own API that is available to use in other custom solutions
if needed.
The following technologies and libraries are used in the CryptoBot For Binance - Cryptocurrency Trading PHP Script:
PHPMLC requires the following software in order to run:
Binance takes commission on each trade. By using following link to register an account, you can benefit 10
percent off on commissions!
https://www.binance.com/en/register?ref=WRS9W5SV
Folder Structure:
The folder structure of the "CryptoBot" folder is as follows:
Move all files from "code" folder to your web server's root or subfolder (like cryptobot). You can use XAMPP for local hosting.
The script should now be accessed by visiting the installed location's url like
"http://localhost/cryptobot/".
Setting up the System:
Navigate to "Settings" page using the link on navbar.
Setting page opens:
System's api url and Binance api keys should be defined in order the script works properly.
System's api url should point to the address of the file "api.php" in script folder.
To get your Binance account api keys, visit Binance API management page and create a new API key if it doesn't
exist.
https://www.binance.com/en/my/settings/api-management
Please make sure that "Enable Reading" and "Enable Spot & Margin Trading" permissions are checked in "API
restrictions" section.
Once you've created your API key, enter API key and API secret key to the related fields in settings page.
API secret key is shown only once when creating API key. If you didn't copied/noted it, please generate a new
API key to get the required keys.
Price check interval is used by the trading interface to trigger api peridically. It is defined as 150 ms by
default.
Binance has several restrictions on its API usage. Please take into the account the "request weight per
minute" hard-limit when changing this value. For more information on the API usage restrictions, please visit
the following link:
https://www.binance.com/en/support/faq/360004492232
For the current weights for API methods, please refer to the documentation:
https://binance-docs.github.io/apidocs/spot/en/#spot-account-trade
Date timezone and date format can be customized using related fields.
For possible values, please refer related pages from the PHP documentation:
https://www.php.net/manual/en/timezones.php
https://www.php.net/manual/en/datetime.format.php
Click "Update" button to save changes.
Even though the user can modify behaviour of the script by implementing his/her own trading strategy using
several parameters, the system has the core business logic to follow.
The general idea is to buy low and sell higher in a perfect situation.
Once the script starts at the time T1, the status becomes "waiting_for_opportunity" and then it continuously
fetches the current price of selected base asset in a quote asset value.
The current price of the asset at a time can be called as C.
In each price update, system compares the value with the previous high and low of the interval.
So the highest (H) and lowest (L) prices of the interval are saved to database to use in buy or sell
decision.
Interval High/Low ratio that should be met to make buy action can be defined by user.
Trend of the price at higher perspective can be useful in order to make buy decision. So user can define first
and second ranges that are before of current time to make comparison of their averages.
Maximum interval can be defined too. If maximum interval duration is exceeded, the new interval will start
automatically.
The user can also trigger creation of market-buy/market-sell order by clicking "Buy Now"/"Sell Now" buttons.
When the buy condition is met, the system creates limit-buy order at current price. Status changes to
"created_buy_order".
In each buy order check interval, the system checks order status. If it's "FILLED", status changes to
"waiting_to_sell".
If auto-sell is enabled, system creates limit-sell order at target price and starts watching status of the
created order.
In good scenario, the order status becomes "FILLED" and transaction completes at a profit.
If unexpected things happen in the market and price starts to fall rapidly and reaches to the point E ("Max.
(Buy Price/Current Price) Ratio" is exceeded), the script can automatically create market-sell order to prevent
further losses if user has activated "escape plan".
Several rules can be enabled according to trader's strategy.
The system can also work in "manual mode" by disabling "Auto-Buy" and "Auto-Sell" settings. In that case the
user can use manual action buttons.
Start/Pause/Stop Buttons:
Start button trigger start/continue of trading process.
Pause button trigger pause of trading process.
Stop button trigger stop of trading process that will reset current interval data including trading status.
Subsequent
Start
Button click will reset status to "Waiting for opportunity".
Reset Interval Button:
Reset Interval button clears interval data such as high/low values and starts new interval
Base and Quote Asset Trading Pair:
The script will call "exchangeInfo" method of Binance Api to fill trading rules automatically so if you're
changing a base or quote asset, you can leave Asset Price
Tick Size and Asset Lot Step Size fields empty. You can manually change them later.
To get most up-to-date information about Trading rules, please visit the following link:
https://www.binance.com/en/trade-rule
Changing base or quote asset will clear all current interval data and trading status.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Base Asset Trading Balance:
The trading balance of base asset.
Sell order quantity is calculated using this value and the price of symbol.
If you are just starting for trade, you can leave this value as "0".
Once the base asset is bought with quote balance, the base asset balance will be automatically increased.
Changing trading pair will reset this value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Quote Asset Trading Balance:
The trading balance of quote asset.
Buy order quantity is calculated using this value and the price of symbol.
If you are just starting for trade, please make sure that the
balance you allocate for trading meets minimum order size.
To get most up-to-date information about Trading rules, please visit the following link:
https://www.binance.com/en/trade-rule
Once the base asset is sold, the quote asset balance will be automatically increased.
Changing trading pair will reset this value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Trading Fee Rate:
Binance take commission on each trade. System takes into account this value to calculate quantity for order.
To guarantee to not get "insufficient balance" errors, it is suggested to leave this value as "0.01" whether or
not using BNB for commissions.
The value is defined as percentage.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Last Sell Price:
After each filled sell order, system records sell price to be considered in "Buying Rule: Min. (Last Sell
Price/Current Price) Ratio" rule if it is enabled.
To change this value, the system should be paused first.
The value is defined as decimal.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Auto-Buy & Auto-Sell:
It is possible to tell script whether to automatically buy or sell if the defined conditions met.
If "Auto-Buy" checkbox is unchecked, the system will wait for user's (Buy Now) action even if there is buying
opportunity.
If "Auto-Sell" checkbox is unchecked, the system will wait for user's (Sell Now) action even if there is selling
opportunity.
The form should be submitted by clicking "Save Changes" button in order to save changes.
Trend Calculation First Duration:
To find out current trend automatically, the script uses two time range to compare averages.
First range can be explained as "from the field value before now to current time".
The value is defined in seconds.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Trend Calculation Second Duration:
To find out current trend automatically, the script uses two time range to compare averages.
Second range can be explained as "from the field value before start of the first range to start of first range".
The value is defined in seconds.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Buy Order Check Interval:
Once limit-buy order is created, script will check its status against filled periodically.
The checking period time in seconds can be customized using this field.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Sell Order Check Interval:
Once limit-sell order is created, script will check its status against filled periodically.
The checking period time in seconds can be customized using this field.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
(Sell Price/Buy Price) Ratio:
To make decision to automatically create limit-sell order, script watches out for each price update if the
current asset price is higher than the buy price at a user defined profit rate.
In example, if you are willing to sell if the current price is higher than 2 percent of the buy-price, then the
"1.02" should be entered as a value.
The form should be submitted by clicking "Save Changes" button or hitting Enter in order to save changes.
Manual Action Buttons:
If the script waits for some condition occurs in order to create buy/sell order but user want to trigger
creation of instant market-buy or market-sell orders, the related button can be clicked.
"Buy Now" button becomes enabled if the current status is "waiting_for_opportunity" or "created_buy_order".
"Sell Now" button becomes enabled if the current status is "waiting_to_sell" or "created_sell_order".
"Cancel" buttons in "Current Buy Order" and "Current Sell Order" areas send cancellation request for the current
order.
Online demo can be accessed using the following link:
https://jetphp.com/cryptobot/demo/
The following images, icons, libraries or other files are used to build the software:
Once again, thank you so much for purchasing CryptoBot For Binance - Cryptocurrency Trading PHP Script. For any kind of bug reports, feedback, feature requests, or even if you just want to say hello, feel free to email me. I'll be really happy about it.
Ovunc Tukenmez